package com.zhdl.hardware.meich_camera;

import com.google.common.eventbus.Subscribe;
import com.zhdl.common.eventbus.center.EventBusCenter;
import com.zhdl.modules.tools.CommonCallback;
import com.zhdl.network.asclltcp.AsciiSendService;
import com.zhdl.network.asclltcp.AscillResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
@Component
@Slf4j
public class MeichCameraCmdHandleDao {
    @Resource
    AsciiSendService sendService;
    CommonCallback<String> callback;
    public void init(){
        EventBusCenter.getEventBus().register(this);
    }
    public void startCamera(CommonCallback<String> callback,int reTry){
        sendService.sendMeichStart(reTry);
        this.callback = callback;
    }
    @Subscribe
    public void receiverData(AscillResult afterStrategyParam){
       String instruction = afterStrategyParam.getInstruction().replaceAll(" ", "");
       instruction = instruction.toUpperCase();
        if (instruction.contains("702C31")){
            log.info("收到相机返回数据"+afterStrategyParam.getData());
            callback.statusCallback(afterStrategyParam.getData());
        }
    }
}
